home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8114 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  49 lines

  1. Path: news.rain.org!usenet
  2. From: "Guus Leeuw jr." <guusl@eiffel.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: system() & error detection
  5. Date: Fri, 01 Mar 1996 08:41:27 -0800
  6. Organization: Interactive Software Engineering Inc. http://www.eiffel.com/
  7. Message-ID: <313728B7.2112A121@eiffel.com>
  8. References: <4gt24g$dba@ncar.ucar.edu>
  9. NNTP-Posting-Host: @outback.eiffel.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
  14. CC: jadams@sage.cgd.ucar.edu
  15.  
  16. James Adams wrote:
  17. > Hello,
  18. >         I am attempting to use the system() call in order to have a
  19. > user-specified command execute in my program.
  20. >         I am wondering how I can check whether or not the command has
  21. > completed successfully ?  I don't want the program to continue if the
  22. > call I make from system() produces some sort of error.  I'd like to be
  23. > able to do something like the following:
  24. >         result = system(command);
  25. >         if (result == ERROR)
  26. >           exit(0);
  27. > Is there anyway to do this ?  Should I be using something other than
  28. > system() ?
  29.  
  30. According to the standard (references are listed with FAQ 19.27),
  31. system() will return -1 upon execution error. Any other value is the
  32. return code of the called program.
  33.  
  34. With execution error is meant that system() cannot perform the task
  35. asked for.
  36.  
  37. The return code of the called program is what you return from main().
  38. For examples `int main(){ return 1; }. The value 1 is the return code.
  39. The caller of this little program has to know how to interpret the
  40. returned value.
  41.  
  42. Hope this helps,
  43.     Guus
  44.